// pages/reserve/reserve.js
import request from '../../service/network.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //弹窗初始值
    titles: ['热门', '距离','商圈','地铁线','大学'],
    
    goods:{
      'remen': { list: ['不限', '春熙路', '天府广场', '宽窄巷子',] },
      'juli': { list: ['不限', '1km', '2km', '3km', '5km', '10km','20km','50km'] },
      'shangquan': { list: ['不限', '春熙路太古里商业区', '锦鲤/武侯祠商圈', '宽窄巷子/中医大商圈','天府广场/盐市口商圈'] },
    },
    currentType: 'juli',
    headerNav:['位置区域','价格星级','智能排序','筛选'],
    // 弹窗初始值
    status:11,
    
    imgurl:"/imgs/reserve/img7.png",
    imgurl1:"/imgs/reserve/reserve-img2.png",
    arriveDate:'08-15',
    leaveDate:'08-16',
    jitian:2,
    type:0,
    headerarry: [
        { id: 0, name: '暑期特惠',select:false },
        { id: 1, name: '信用住', select: false},
        { id: 2, name: '双床', select: false},
        { id: 3, name:  '含早', select: false },
        { id: 4, name: '低价高端', select: false },
        { id: 5, name: '可取消', select: false },
    ],
    hotellist: [],
    current: 1,
    size: 3,
    id:0
  },
  show1(e){
    // debugger
    
    let item=e.currentTarget.dataset.id;
    
    let isSelect = !item.select;
    
    // if(item.select){
    //   isselect = item.select
    // }
    // else{
    //   isselect = item.select
    // }
    let arr = this.data.headerarry;
    let newArray = [];
    arr.forEach(element=> {
      
      
      if(element.id===item.id){
        
        element.select=isSelect;
      };
      newArray.push(element)
    });
    
    this.setData({
      headerarry: newArray
    })
  

  },
  // show2() {
  //   let type = 1;
  //   this.setData({
  //     type: type
  //   })
  // },

  //弹窗点击事件
  titleclick(e){
     
    let currentType = ''
    switch (e.detail.index) {
      case 0:
        currentType = 'remen'
        break
      case 1:
        currentType = 'juli'
        break
      case 2:
        currentType = 'shangquan'
        break
    }
    this.setData({
      currentType: currentType
    })
    console.log(this.data.currentType);
  },
  //隐藏弹窗
  hidden(e){
    console.log(e);
    let index=e.detail.index
    this.setData({
      status: 11,
      
    })
    
  },
  headerclick(e){
    
    let index=e.detail.index;
    this.setData({
      status: index

    })
  },
  //点击搜索
  sousuo(){
    
    wx.navigateTo({
      url: '../firstplace/firstplace',
    })
  },
  //点击酒店详情
  hotelDetails:function(e){
    
    let id=e.currentTarget.dataset.item.id;
    wx.navigateTo({
      url: '../../pages/hotelDetails/hotelDetails?id='+id,
      
    })
  },
 //用户评价
  userEvaluation:function(){
    wx.navigateTo({
      url: '../../pages/userEvaluation/userEvaluation',
    })
  },
  //跳转评价
  dingdan(){
    wx.navigateTo({
      url: '/pages/allOrders/allOrders',
    })
  },
  //日期
  riqi(){
    wx.navigateTo({
      url: '/pages/calendar/calendar',
    })
  },
  //发送网络请求
  sendAjax() {
    //let that = this;
    request({
      url: 'microHotelBook/hotelByCondiList',
      method: 'post',
      data: {
        'current': this.data.current,
        'size': this.data.size
      }
    }).then(res => {
      
      let hotellist = this.data.hotellist;
      
      let hotellist1 = res.data.data.records;
      hotellist.push(...hotellist1);
      
      this.setData({
        hotellist: hotellist
      })
    }).catch(err => {
      
      wx.showToast({
        title:'网络错误',
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  
  onLoad: function (options) {
    this.sendAjax()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  //上拉加载更多
  moreLoad: function () {
    let current = this.data.current;
    // let size=this.data.size
    // size=size+3;
    current++;
    this.setData({
      current: current,

    })
    

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.moreLoad();
    this.sendAjax();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})